<?php
require_once 'RegistrerView.php'; //Behövs EJ
require_once 'LoginView.php'; //Behövs EJ
require_once 'TextStringOutput.php'; //Behövs EJ

class ProductView {
	
	const AllFigures = "alla";
	const AllSmurfs = "allasmurfar";
	const AllStarWars = "allastarwars";
	const ShowItem = "figur";
	const Price = "price";
	const BuyButton ="buyproduct";
	const ProductDoesntExist = "<p id='textStringWrong'>Produkten ni söker finns ej</p>";
	private $m_userBuyButton = "didBuyProduct"; 
	
	

	// Alla produkter och olika kategorier
	public function ShowCategoryMenuAndProduct ($product) {
		
		$returnString = "";
		$returnString .="
		<div id='category'>
			<h2 class='buttonLink'>
				<a href='?" . ProductView::AllFigures ."=". ProductView::AllFigures  ."'/>Alla figurer</a>
				<a href='?". ProductView::AllStarWars ."=". ProductView::AllStarWars ."'/>Star Wars</a>
				<a href='?". ProductView::AllSmurfs ."=". ProductView::AllSmurfs ."'/>Smurfar</a>
			</h2>
		<table>
			<thead>
				<tr>
					<th>Namn:</th>
					<th>SEK:</th>
				</tr>
			</thead>
			<tbody>";
			foreach ($product as $product) {
				$returnString .= "<tr>";
				foreach ($product as $info){
					if($info == $product->m_price){
						$returnString .=  "<td class='price'>$info</td>";
						
					}elseif($info == $product->m_productname){
						$returnString .=  "<td class='name'><a href='?". ProductView::ShowItem. "=". $product->product_pk ."&".ProductView::Price."=".$product->m_price."'/>$info</a></td>";
					}
					else{
						continue;
					}
				}
				
				$returnString .= "</tr>";
			}

		$returnString .= "
		</tbody>
		</table>
		</div>";
		
		return $returnString;
	}

	// En enskild produkt
	public function ShowSpecifikProductAndMenu ($specificproduct) {

		$returnString = "";
		$returnString .="
		<div id='category'>
			<h2 class='buttonLink'>
				<a href='?" . ProductView::AllFigures ."=". ProductView::AllFigures  ."'/>Alla figurer</a>
				<a href='?". ProductView::AllStarWars ."=". ProductView::AllStarWars ."'/>Star Wars</a>
				<a href='?". ProductView::AllSmurfs ."=". ProductView::AllSmurfs ."'/>Smurfar</a>
			</h2>
		<table>
			<thead>
				<tr>
					<th>Namn:</th>
					<th>SEK:</th>
					<th>Beskrivning:</th>
					<th>Bild:</th>
				</tr>
			</thead>
			<tbody>";
				$returnString .= "<tr>";
					$returnString .=  "<td class='name' >$specificproduct->m_productname</td>";
					$returnString .=  "<td class='price' >$specificproduct->m_price</td>";
					$returnString .=  "<td class='text'>$specificproduct->m_description
				<form action='' method='post' class='buyButton'>
					<input type='submit' class='registrerButton' name='" . ProductView::BuyButton ."' id='productId' value='Lägg i varukorgen' />
				</form>
				</td>";
				$returnString .=  "<td><img src='$specificproduct->m_picture' alt='En bild' class='picture' /></td>";
				$returnString .= "</tr>";
		$returnString .= "
		</tbody>
		</table>
		</div>";
		return $returnString;
	}		
	
	//Lägger till felmeddellande
	public function AddErrorMessage($specificArray){
		return ProductView::ProductDoesntExist;
	}

}